package com.xzjt.exception;

import com.xzjt.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.NoHandlerFoundException;

/**
 * @ClassName: GlobalExceptionHandler
 * @Author: yuandong
 * @Date 2021/10/9 9:00
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {



    /**
     * 通用异常处理
     *
     * @param e
     * @return
     */
    @ExceptionHandler(Exception.class)
    public R publicException(Exception e) {
        log.error("全局异常>>>>>>>>>>>", e);
        if (e instanceof NoHandlerFoundException) {
            return R.notFound();
        } else {
            return R.exception();
        }
    }
}
